/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package de.hwrberlin.remo.model.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import de.hwrberlin.remo.model.ElementState;
import de.hwrberlin.remo.model.KnowledgeBaseElement;
import de.hwrberlin.remo.model.LinksFromFacts;
import de.hwrberlin.remo.model.LinksFromRules;
import de.hwrberlin.remo.model.RemoModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Knowledge Base Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.hwrberlin.remo.model.impl.KnowledgeBaseElementImpl#getRelatedlinkedrules <em>Relatedlinkedrules</em>}</li>
 *   <li>{@link de.hwrberlin.remo.model.impl.KnowledgeBaseElementImpl#getId <em>Id</em>}</li>
 *   <li>{@link de.hwrberlin.remo.model.impl.KnowledgeBaseElementImpl#getRelatedlinkedfacts <em>Relatedlinkedfacts</em>}</li>
 *   <li>{@link de.hwrberlin.remo.model.impl.KnowledgeBaseElementImpl#getState <em>State</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class KnowledgeBaseElementImpl extends RemoObjectImpl implements KnowledgeBaseElement {
	/**
	 * The cached value of the '{@link #getRelatedlinkedrules() <em>Relatedlinkedrules</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelatedlinkedrules()
	 * @generated
	 * @ordered
	 */
	protected EList<LinksFromRules> relatedlinkedrules;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final int ID_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected int id = ID_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRelatedlinkedfacts() <em>Relatedlinkedfacts</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelatedlinkedfacts()
	 * @generated
	 * @ordered
	 */
	protected EList<LinksFromFacts> relatedlinkedfacts;

	/**
	 * The default value of the '{@link #getState() <em>State</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getState()
	 * @generated
	 * @ordered
	 */
	protected static final ElementState STATE_EDEFAULT = ElementState.TRUE;

	/**
	 * The cached value of the '{@link #getState() <em>State</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getState()
	 * @generated
	 * @ordered
	 */
	protected ElementState state = STATE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected KnowledgeBaseElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RemoModelPackage.Literals.KNOWLEDGE_BASE_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LinksFromRules> getRelatedlinkedrules() {
		if (relatedlinkedrules == null) {
			relatedlinkedrules = new EObjectWithInverseResolvingEList<LinksFromRules>(LinksFromRules.class, this, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES, RemoModelPackage.LINKS_FROM_RULES__ELEMENT);
		}
		return relatedlinkedrules;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(int newId) {
		int oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LinksFromFacts> getRelatedlinkedfacts() {
		if (relatedlinkedfacts == null) {
			relatedlinkedfacts = new EObjectWithInverseResolvingEList<LinksFromFacts>(LinksFromFacts.class, this, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS, RemoModelPackage.LINKS_FROM_FACTS__ELEMENT);
		}
		return relatedlinkedfacts;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ElementState getState() {
		return state;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setState(ElementState newState) {
		ElementState oldState = state;
		state = newState == null ? STATE_EDEFAULT : newState;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__STATE, oldState, state));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getRelatedlinkedrules()).basicAdd(otherEnd, msgs);
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getRelatedlinkedfacts()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				return ((InternalEList<?>)getRelatedlinkedrules()).basicRemove(otherEnd, msgs);
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				return ((InternalEList<?>)getRelatedlinkedfacts()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				return getRelatedlinkedrules();
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__ID:
				return getId();
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				return getRelatedlinkedfacts();
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__STATE:
				return getState();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				getRelatedlinkedrules().clear();
				getRelatedlinkedrules().addAll((Collection<? extends LinksFromRules>)newValue);
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__ID:
				setId((Integer)newValue);
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				getRelatedlinkedfacts().clear();
				getRelatedlinkedfacts().addAll((Collection<? extends LinksFromFacts>)newValue);
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__STATE:
				setState((ElementState)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				getRelatedlinkedrules().clear();
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__ID:
				setId(ID_EDEFAULT);
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				getRelatedlinkedfacts().clear();
				return;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__STATE:
				setState(STATE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDRULES:
				return relatedlinkedrules != null && !relatedlinkedrules.isEmpty();
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__ID:
				return id != ID_EDEFAULT;
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS:
				return relatedlinkedfacts != null && !relatedlinkedfacts.isEmpty();
			case RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__STATE:
				return state != STATE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (id: ");
		result.append(id);
		result.append(", state: ");
		result.append(state);
		result.append(')');
		return result.toString();
	}

} //KnowledgeBaseElementImpl
